package com.jiukuaidao.library.util;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.Toast;

import com.jiukuaidao.library.Config;
import com.jiukuaidao.library.R;
import com.jiukuaidao.library.common.AppManager;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Author : BinarySatan
 * Date : 2016/5/17
 * Description :
 */
public class ActivityUtils {

    /**
     * add fragment
     */
    public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager,
                                             @NonNull Fragment fragment, int frameId) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(frameId, fragment);
        transaction.commit();
    }


    private static boolean mIsWaitingExit = false;

    public static void exitApp() {
        if (mIsWaitingExit) {
            mIsWaitingExit = false;
            AppManager.getAppManager().AppExit(Config.mContext);
        } else {
            Toast.makeText(Config.mContext, Config.mContext.getResources().getString(R.string.exitApp), Toast.LENGTH_SHORT).show();

            mIsWaitingExit = true;

            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    mIsWaitingExit = false;
                }
            }, 3000);
        }
    }


}
